package com.xtck.ha.fault.core.controller;

import com.xtck.ha.common.core.constant.HttpStatus;
import com.xtck.ha.common.core.utils.poi.ExcelUtil;
import com.xtck.ha.common.core.web.controller.BaseController;
import com.xtck.ha.common.core.web.domain.AjaxResult;
import com.xtck.ha.common.core.web.page.TableDataInfo;
import com.xtck.ha.fault.core.model.DsFMEAInfo;
import com.xtck.ha.fault.core.service.DsFMEAInfoService;
import com.xtck.ha.fault.framework.utils.JsonResult;
import com.xtck.ha.fault.modules.convert.FmeaInfoConvert;
import com.xtck.ha.fault.modules.pojo.entity.FmeaInfo;
import com.xtck.ha.fault.modules.pojo.vo.FmeaInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型列表 controller
 *
 * @ClassName: DsFMEAInfoController
 * @Description: 外部访问接口
 * @author liuyuan
 * @date 2025-07-02
 */
@Api(tags = "故障分析信息管理")
@RestController
@RequestMapping("/fmeaInfo")
public class DsFMEAInfoController extends BaseController {

    @Autowired
    private DsFMEAInfoService dsFMEAInfoService;


    @ApiOperation("分页查询故障分析信息列表")
    @GetMapping("/page")
    public AjaxResult page(DsFMEAInfo dsFMEAInfo)
    {
        startPage();
        List<DsFMEAInfo> list = dsFMEAInfoService.selectTList(dsFMEAInfo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setList(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(dsFMEAInfoService.count(dsFMEAInfo));
        return AjaxResult.success(rspData);
    }

    @ApiOperation("列表查询故障分析信息")
    @GetMapping("/list")
    public List<DsFMEAInfo> list(DsFMEAInfo dsFMEAInfo)
    {
        List<DsFMEAInfo> list = dsFMEAInfoService.selectTList(dsFMEAInfo);
        return list;
    }

    @ApiOperation("导出故障分析信息列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DsFMEAInfo dsFMEAInfo)
    {
        List<DsFMEAInfo> list = dsFMEAInfoService.selectTList(dsFMEAInfo);
        ExcelUtil<DsFMEAInfo> util = new ExcelUtil<>(DsFMEAInfo.class);
        util.exportExcel(response, list, "样例数据");
    }

    @ApiOperation("获取$故障分析信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dsFMEAInfoService.selectTById(id));
    }

    @ApiOperation("新增$故障分析信息")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DsFMEAInfo dsFMEAInfo)
    {
        return toAjax(dsFMEAInfoService.insertT(dsFMEAInfo));
    }

    @ApiOperation("修改故障分析信息")
    @PutMapping
    public AjaxResult update(@RequestBody DsFMEAInfo dsFMEAInfo)
    {
        int i = dsFMEAInfoService.updateT(dsFMEAInfo);
        return toAjax(i);
    }

    @ApiOperation("删除故障分析信息")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dsFMEAInfoService.deleteTByIds(ids));
    }

    @GetMapping("/taskId={taskId}")
    @ApiOperation(value = "获取任务执行结果")
    public AjaxResult getByTaskId(@PathVariable("taskId") Long taskId){
        DsFMEAInfo entity = dsFMEAInfoService.getByTaskId(taskId);
        return AjaxResult.success(entity);
    }



}
